const {login, register } = require('../../Dao/user/user-loginDao');

const bcryptjs = require('bcryptjs');
 
module.exports.login = async function ({name,password,type,ice}) {
 
    const [users] = await login({name,password,type,ice});
    //console.log(22,users);
    if (users) {
        // console.log(password+'左传入，右数据库'+users.password);
        // 比较真实密码和加密密码是否相等
        // const data = bcryptjs.compareSync(password, users.password);
        if (password== users.password) {
            return {
                msg: '登录成功',
                success: true,
                type
            }
    } else {
        return {
            msg: '密码错误或账号不存在',
            success: false
        }
    }
}}

module.exports.register = async function (user) {
    const data = await register(user);
    if (data._id) {
        return {
            msg: '注册成功',
            success: true
        }
    }
    return {
        msg: '注册失败',
        success: false
    }
}